
// 公共头部
import myHeader from "/pages/headerfoot/pages/header.vue";
//公共底部
import Tabbar from '/pages/headerfoot/pages/hitgamefooter.vue'

//打帮赛方法
import hitmatchcommon from '@/common/hitmatchcommon.js';
//cache缓存
import Cache from '@/utils/cache.js';
//基础
import Base from '@/common/base.js'


export default {
	 components: {myHeader,Tabbar},
	data() {
		return {
			list:[],//赛事
			userList:[],//用户列表 
			page:1,//页数
			make_id:0,//赛事
			makecount:0,//次数
			sharid:'',//分享人
			sharedata:[],//分享数据
		}
	},
	
	onLoad(option) {
		console.log(option);
		var that=this;
		that.userList=[];//用户列表 
		 that.make_id=option.id;
		 // that.make_id=1;
		 that.getMake();//得到赛事参赛列表
		 that.getMakeUserList();//得到赛事参赛列表
		 that.getUserAccount(); //获取用户赛事次数
		 //禁止分享朋友圈
		 uni.hideShareMenu({
		         menus: ['shareTimeline']
		  })
		   that.getUserShare(); //获取用户分享
		  //分享获取
		  if(option.shareid){
			  Cache.set('shareid'+that.make_id,option.shareid,86400);
			  that.shareid=option.shareid;
			  console.log('----');
			   console.log(Cache.get('shareid'+that.make_id));
			   console.log('----');
		  }
		
		  
	},
	onReachBottom(){
		var that=this;
		that.page=that.page+1;
		
	},
	// 1.发送给朋友
	onShareAppMessage() {
		var that=this;
	    that.getUserShare();//用户分享接口
		console.log(that.sharedata.usershare_make_url);
		return {
			title: that.sharedata.usershare_make_title,
			path:that.sharedata.usershare_make_url,
			imageUrl:  that.sharedata.usershare_make_img,
		}
	},
	methods: {
 
		//用户分享接口
		async getUserShare() {
			var that = this;
			var data = {};
			data['make_id']=that.make_id;
			data['page']=that.page;
			data['make_user_id']=Cache.get('user_id');
			await hitmatchcommon.getUserShareapiLibMethod(data).then(res => {
				if (res) {
					 that.sharedata=res;
				}
			});
		},
		//得到赛事参赛列表
		async getMakeUserList() {
			var that = this;
			var data = {};
			data['make_id']=that.make_id;
			data['page']=that.page;
			hitmatchcommon.getMakeUserListLibMethod(data).then(res => {
				if (res) {
					that.userList = that.userList.concat(res);//赛事参赛列表
				}
			});
		},
		//获取赛事
		async getMake() {
			var that = this;
			var data = {};
			data['make_id']=that.make_id;
			data['make_user_id']=Cache.get('user_id');
			hitmatchcommon.getMakeLibMethod(data).then(res => {
				if (res) {
					that.list = res; //赛季列表
				}
			});
		},
		//获取用户赛事次数
		getUserAccount(){
			 var that = this;
			 var data = {};
			 data['make_id']=that.make_id;
			 data['make_user_id']=Cache.get('user_id');
			 hitmatchcommon.getUserAccountapiLibMethod(data).then(res => {
					 if(res){
						that.makecount=res.make_number; 
					 }
		 
			 });
		},
		 //报名比赛
		 appalymatch(){
			 console.log("报名比赛");
		 	 var that = this;
		 	 var data = {};
		 	 data['make_id']=that.make_id;
		 	 data['make_user_id']=Cache.get('user_id');
			data['shareid']= Cache.get('shareid'+that.make_id);
		 	 hitmatchcommon.gsetApplicationLibMethod(data).then(res => {
		 		if (res.code==10000) {
		 			 Base.publicshowtoasterror(res.msg);
		 		}else{
		 			 Base.publicshowtoastsuccess('报名成功');
					 Base.reload();
		 		}
		 	 });
		 },
		//进入比赛
		inmatch(){
			 var that = this;
			 var data = {};
			 if(that.makecount>0){
			 uni.navigateTo({
			 	url:hitmatchcommon.automaticurl('matcheslist')+"?id="+that.make_id,
			 })
			 }else{
				 Base.publicshowtoasterror('次数不足,请分享或者购买.');
			 }
			
		},
	}
}
